import requests


class KDApi:

    @classmethod
    def get_image_code(cls):
        code_url = "http://kdtx-test.itheima.net/api/captchaImage"
        code_resp = requests.get(code_url)
        return code_resp

    @classmethod
    def login_api(cls, login_body):
        login_url = "http://kdtx-test.itheima.net/api/login"
        login_header = {"Content-Type": "application/json"}

        login_resp = requests.post(url=login_url, headers=login_header, json=login_body)
        return login_resp

    # 新增课程
    @classmethod
    def add_course_api(cls, token, body):
        url = "http://kdtx-test.itheima.net/api/clues/course"
        headers = {"Content-Type": "application/json", "Authorization": token}
        resp = requests.post(url=url, headers=headers, json=body)
        return resp

    # 查询课程
    @classmethod
    def query_course_api(cls, token):
        url = "http://kdtx-test.itheima.net/api/clues/course/list"
        headers = {"Authorization": token}
        resp = requests.get(url=url, headers=headers)
        return resp

    # 修改课程
    @classmethod
    def change_course_api(cls, token, body):
        url = "http://kdtx-test.itheima.net/api/clues/course"
        headers = {"Content-Type": "application/json", "Authorization": token}
        resp = requests.put(url=url, headers=headers, json=body)
        return resp

    # 删除课程
    @classmethod
    def del_course_api(cls, token, course_id):
        url = f"http://kdtx-test.itheima.net/api/clues/course/{course_id}"
        headers = {"Authorization": token}
        resp = requests.delete(url=url, headers=headers)
        return resp
